package gamble.qna.command;

import gamble.qna.dao.BoardDaoImp;
import gamble.qna.vo.BoardVO;
import gamble.qna.vo.PageVO;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

public class SearchController {
	 
	private BoardDaoImp dao;
	List<BoardVO> list;
    PageVO pv;
    int currentPage=1; //현재 페이지번호
    int blockCount=10; //한페이지당 보여줄 레코드 수
    int blockPage=2; //한 블록당 보여줄 페이지 수
	
	
	public void setDao(BoardDaoImp dao) {
		this.dao = dao;
	}


	@RequestMapping("/search.js")
	protected ModelAndView listMethod(PageVO pv){
		String subject=pv.getSearch();
		
		int str=pv.getCurrentPage();
		currentPage=(str==0  ? 1 :str);
		int totalCount=dao.getSearch2(pv);		
		if(totalCount>=0){
		 	 pv=new PageVO(currentPage,totalCount,blockCount,blockPage);
		 	 list=dao.getSearch(subject);  
		 	 System.out.println("ddd:"+list.size());
		}
		
		ModelAndView mv=new ModelAndView();
		mv.addObject("currentPage",currentPage);
		mv.addObject("list",list);
		mv.addObject("pv",pv);
		mv.setViewName("list");
		return mv;
	}
}
